﻿import QtQuick 2.0

Rectangle{
    property var dataModle
    signal select()
    signal connect()

    height: 90
    color: "#20212C"
    border.width: 0

    Image{
        id: vehicleIcon
        x: 36
//        source: vehicleState.text == "远程模式" ? "qrc:/imgs/.png" : "qrc:/imgs/pdj_2.png"
        sourceSize.width: 67
        sourceSize.height: 30
        anchors.verticalCenter: parent.verticalCenter
    }
    Text {
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: vehicleIcon.right
        anchors.leftMargin: 17
        color: "white"
        text: dataModle.name
        font{
            family: "Microsoft YaHei"
            pixelSize: 20
        }
    }
    Rectangle{
        id:  vehicleLight
        color: "#8D8D8D"
        width: 11
        height: 11
        radius: 11
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: vehicleIcon.right
        anchors.leftMargin: 201
    }
    Text {
        id: vehicleState
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: vehicleIcon.right
        anchors.leftMargin: 219
        text: "离线"
        color: Qt.rgba(171, 176, 224, 0.8)
        font{
            family: "Microsoft YaHei"
            pixelSize: 20
        }
    }

    Rectangle{
        id: connectBtn
        width: 193
        height: 67
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 69
        radius: 8
        border.width: 0
        color: connectBtn.enabled ? "dodgerblue" : Qt.rgba(255, 255, 255, 0.5)
        Text{
            id: connectText
            anchors.centerIn: parent
            text: "连接"
            color: connectBtn.enabled ? "white" : Qt.rgba(255, 255, 255, 0.1)
            font{
                family: "Microsoft YaHei"
                pixelSize: 28
            }
        }
        MouseArea{
            anchors.fill: parent
            onClicked: {
                if(vehicleState.text=="远程模式")
                {
                    connect() //连接车辆
//                    vehicleState.text = "远程驾驶中"
//                    vehicleLight.color = "#FFC701"
                }
            }
            Component.onCompleted: {
                if(vehicleState.text!="远程模式")
                {
                    connectBtn.enabled = false
                    connectBtn.color = Qt.rgba(255, 255, 255, 0.5)
                    connectText.color = Qt.rgba(255, 255, 255, 0.1)
                }
            }
        }
    }

    MouseArea{
        anchors.right: connectBtn.left
        height: parent.height
        width: 998
        onClicked: {
            select()
        }
    }

    onDataModleChanged: {
        if(dataModle.state === "在线"){
//           if(!grader_can.remote_state){
               vehicleState.text = "远程模式"
               vehicleLight.color = "#06FF96"
//           }else{
//               vehicleState.text = "本地模式"
//               vehicleLight.color = "#FFC701"
//           }
        }else{
            vehicleState.text = "离线"
            vehicleLight.color = "#8D8D8D"
        }

        if(dataModle.type === "grader"){
            vehicleIcon.source = ""
            vehicleIcon.source = vehicleState.text == "远程模式" ? "qrc:/imgs/grader_icon.png" : "qrc:/imgs/grader_icon_2.png"
        }else if(dataModle.type === "loader"){
            vehicleIcon.source = ""
            vehicleIcon.source = vehicleState.text == "远程模式" ? "qrc:/imgs/digger_icon.png" : "qrc:/imgs/digger_icon_2.png"
        }
    }
}
